package org.zoomdev.zoom.common.caster;


import java.lang.reflect.Type;

class FirstVisitValueCaster implements ValueCaster {

    Type dest;

    ValueCaster caster;

    public FirstVisitValueCaster(Type dest) {
        assert (dest != null);
        this.dest = dest;
    }

    @Override
    public Object to(Object src) {
        ValueCaster caster = this.caster;
        if (caster == null) {
            caster = Caster.wrapType(src.getClass(), dest);
            this.caster = caster;
        }

        return caster.to(src);
    }
}
